using System.ComponentModel.DataAnnotations.Schema;
using UniversalAdminSystem.Domian.Core;
using UniversalAdminSystem.Domian.Core.ValueObjects;
using UniversalAdminSystem.Domian.FileStorage.ValueObjects;
using UniversalAdminSystem.Domian.knowledge.ValueObj;

namespace UniversalAdminSystem.Domian.knowledge.Aggregates;


public class DocumentChunk : AggregateRoot
{
    public ChunkId Id { get; private set; } = null!;

    public FileId FileId { get; private set; } = null!;

    public string Content { get; private set; } = string.Empty;

    public TextEmbedding Embedding { get; private set; } = null!;
    [NotMapped] // EF Core 不会映射到表
    public double SimilarityScore { get; set; }
    public FileAccessLevel Level { get; private set; }

    protected DocumentChunk() { }

    private DocumentChunk(ChunkId id, FileId fileId, string content, TextEmbedding embedding, FileAccessLevel level)
    {
        Id = id;
        FileId = fileId;
        Content = content;
        Embedding = embedding;
        Level = level;
    }

    public static DocumentChunk CreateDocumentChunk(ChunkId id, FileId fileId, string content, TextEmbedding embedding, FileAccessLevel level = FileAccessLevel.Public)
    {
        if (string.IsNullOrWhiteSpace(content))
        {
            throw new ArgumentException("内容不能为空");
        }

        if (embedding == null)
        {
            throw new ArgumentException("嵌入向量不能为空");
        }

        return new DocumentChunk(id, fileId, content, embedding, level);
    }


}